/* Copyright Thanh-Trung Pham, JAIST, 2013 */

package jp.ac.jaist.input;

import jp.ac.jaist.MVPStructureType;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Thanh-Trung Pham
 */
public class RMPErrorPropertyVectorWrapper {
    private Map<Integer, Double> m_oErrorPropertyVector;

    /**
     * The constructor.
     * @param errorPropertyVector the error property vector from the input model.
     */
    public RMPErrorPropertyVectorWrapper(MVPStructureType.ErrorPropertyVector errorPropertyVector) {
        RMPInputModelManager oInputModelManager = RMPInputModelManager.getInstance();

        m_oErrorPropertyVector = new HashMap<Integer, Double>();

        for(MVPStructureType.ErrorPropertyVector.ForFailureType oForFailureType: errorPropertyVector.getForFailureTypeArray()){
            int iFTIndex = oInputModelManager.getFailureTypeIndex(oForFailureType.getForFailureType());
            m_oErrorPropertyVector.put(iFTIndex, oForFailureType.getProbability());
        }
    }

    /**
     * Get the error property probability for the given failure type index.
     * @param failureTypeIndex the failure type index.
     * @return he error property probability for the given failure type index.
     */
    public double getProbability(int failureTypeIndex){
       if(!m_oErrorPropertyVector.containsKey(failureTypeIndex)){
           return 0;
       }

        return m_oErrorPropertyVector.get(failureTypeIndex);
    }

    /**
     * Get the error property probability for the given failure type.
     * @param failureType the failure type.
     * @return he error property probability for the given failure type.
     */
    public double getProbability(String failureType){
        RMPInputModelManager oInputModelManager = RMPInputModelManager.getInstance();
        int iFailureTypeIndex = oInputModelManager.getFailureTypeIndex(failureType);

        if(!m_oErrorPropertyVector.containsKey(iFailureTypeIndex)){
            return 0;
        }

        return m_oErrorPropertyVector.get(iFailureTypeIndex);
    }


}
